/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.MachineManagement;

import Beans.Requests.RequestBean;
import Utilities.Functions;

/**
 * This is the superclass for all machine management requests.
 *
 * @author Angel Sanadinov
 */
public abstract class MachineManagementRequest extends RequestBean
{
    private String machineId;   //id of the machine associated with the request

    /**
     * No-argument constructor. <br><br>
     * All fields are set to their invalid values.
     */
    public MachineManagementRequest()
    {
        super();
        this.machineId = null;
    }

    /**
     * Sets the machine id for this request.
     *
     * @param machineId the id of the machine
     */
    public void setMachineId(String machineId)
    {
        this.machineId = machineId;
    }

    /**
     * Retrieves the id of the machine associated with this request.
     *
     * @return the machine id
     */
    public String getMachineId()
    {
        return machineId;
    }

    /**
     * Checks if the machine id associated with the request is valid.
     *
     * @return <code>true</code> if the machine id is valid or <code>false</code>
     *         otherwise
     */
    protected boolean isMachineIdValid()
    {
        return Functions.isUUIDValid(machineId);
    }

    /**
     * Checks the validity of the request. <br><br>
     *
     * A request is considered valid only if all of the supplied data is valid.
     *
     * @return <code>true</code> if the request is valid or <code>false</code> otherwise
     */
    @Override
    public boolean isValid()
    {
        if(isRequestedActionValid() && isRequestorIdValid() && isServerIdValid())
            return true;
        else
            return false;
    }
}
